package org.example.downloadtest.ctl;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class HomeCtl {
    @GetMapping("/")
    public ModelAndView home() throws IOException {
        ModelAndView modelAndView=new ModelAndView("index");
        List<String> filenames=Files.list(Paths.get("C:/Users/zhjun/Downloads"))
                        .map(path->{
                            return path.toFile().getName();
                        })
                                .collect(Collectors.toList());
        modelAndView.addObject("files",filenames);
        return modelAndView;
    }
}
